$(function(){
	
	var user='admin';
	
	function sendUser(name){
		user = name;
	}
	
	//获取总页数
	$.getJSON('../../AllPages',{
		flag:'form'
	},function(data,status){
		if(status){
			console.log(data[0].pages);
			var pages = data[0].pages;
			
			$('#pageLimit').bootstrapPaginator({
				currentPage : 1,
				totalPages : parseInt(pages),
				size : "normal",
				bootstrapMajorVersion : 3,
				alignment : "right",
				numberOfPages : 5,
				itemTexts : function(type, page, current) {
					switch (type) {
					case "first":
						return "首页";
					case "prev":
						return "上一页";
					case "next":
						return "下一页";
					case "last":
						return "末页";
					case "page":
						return page;
					}
				},

				onPageClicked : function(event, originalEvent, type, page) {
					console.log("1:" + page);
					
					allDealPage(page);
					
//					console.log(page);
				},
			});
			
			
			
		}
	});
	
	
	//显示第一页
	allDealPage(1);
	
	function allDealPage(page){
		$.getJSON('../../DealInfoPage',{
			pageShowNumber:5,
			currentPage:page
		},function(data,status){
			
			$('tbody').empty();
			for(var i=0;i<data.length;i++){
				
				if(data[i].FORM_STATUS == '已发货'){
					$('tbody').append('<tr><td>'+data[i].SALED_ID+'</td><td>'+data[i].VIP_NAME+'</td><td>'
							+data[i].ANIMAL_ID+'</td><td>'+data[i].ADDRESS+'</td><td>'+data[i].PEOPLE+'</td><td>'
							+data[i].PHONE+'</td><td>'+data[i].SALE_DATE+'</td><td>'
							+'<form role="form"action="../../DealInfoPage"><div class="form-group has-success">'
							+'<select name="form-status" class="form-control">'
							+'<option>'+data[i].FORM_STATUS+'</option><option>已签收</option></select>'
							+'</div><div class="form-group" style="display:none">'
							+'<input type="text" name="form-id" value="'+data[i].SALED_ID+'">'
							+'<input type="text" name="flag" value="1"></div><div class="form-group"> '
							+'<input type="text" name="form-dealer"disabled="disabled"class="form-control" '
							+'value="处理者：'+user+'"></div><div class="form-group">'
							+'<button type="submit" class="btn btn-default">确定</button></div></form></td></tr>');
				}else if(data[i].FORM_STATUS == '未处理'){
					$('tbody').append('<tr><td>'+data[i].SALED_ID+'</td><td>'+data[i].VIP_NAME+'</td><td>'
							+data[i].ANIMAL_ID+'</td><td>'+data[i].ADDRESS+'</td><td>'+data[i].PEOPLE+'</td><td>'
							+data[i].PHONE+'</td><td>'+data[i].SALE_DATE+'</td><td>'
							+'<form role="form"action="../../DealInfoPage"><div class="form-group has-success">'
							+'<select name="form-status" class="form-control">'
							+'<option>'+data[i].FORM_STATUS+'</option><option>已发货</option></select>'
							+'</div><div class="form-group">'
							+'<input type="text" name="form-dealer" disabled="disabled"class="form-control" '
							+'value="处理者：'+user+'"></div><div class="form-group" style="display:none"> '
							+'<input type="text" name="form-id" value="'+data[i].SALED_ID+'"><input type="text" name="flag" value="1"></div><div class="form-group">'
							+'<button type="submit" class="btn btn-default">确定</button></div></form></td></tr>');
				}else{//签收
					$('tbody').append('<tr><td>'+data[i].SALED_ID+'</td><td>'+data[i].VIP_NAME+'</td><td>'
							+data[i].ANIMAL_NAME+'</td><td>'+data[i].ADDRESS+'</td><td>'+data[i].PEOPLE+'</td><td>'
							+data[i].PHONE+'</td><td>'+data[i].SALE_DATE+'</td><td>'+data[i].FORM_STATUS+'</td></tr>');
				}
				
				
				
			}
			
		});
	}
	
//	<form role="form"><div class="form-group has-success"><select name="form-status" class="form-control"><!-- 需要原因 sql --><option>已发货</option></select></div><div class="form-group"><label></label> <input type="text" disabled="disabled"class="form-control" value="处理者：xxx"></div><div class="form-group" style="display: none"><button type="submit" class="btn btn-default">确定</button></div></form>
	
	
})